import React, { Component } from 'react';
import { LocaleProvider, Icon } from 'antd';
import zh_CN from 'antd/lib/locale-provider/zh_CN';
import QueryInfo from '../../../components/QueryInfo';
import TableInfo from '../../../components/TableInfo';
import TitleBtn from '../../../components/TitleBtn';
import { requestService } from '../../../service/apply'
import './All.less';

class All extends Component {
  constructor(props) {
    super(props);
    this.state = {
      requestData: []
    }
  }

  newData = [];

  getRequestData = async () => {
    const res = await requestService.request_list();
    console.log(res.data);
    res.data.rows.forEach((item) => {
      this.newData.push({
        key: item.id,
        name: item.name,
        phone: item.tel,
        zcTime: item.regdate,
        sqTime: item.reqdate,
        tg: item.pcode ? item.pcode : '-',
        sqMoney: item.money,
        sqqx: item.cycle,
        jqCount: item.nums,
        sqCount:1,
        fc:60,
        shfs: item.rmethod,
        shState: item.state === 0 ? ['待机审'] : item.state === 1 ? ['机审中'] : item.state === 2 ? ['待人工审核'] : item.state === 3 ? ['审核中'] : ['已审核'],
        shPerson: item.checkname ? item.checkname : '-',
        MOPerson:'-',
        shResult: item.ustate === 0 ? ['拒绝'] : [''],
        cz:['立即领取'],
        qx:['取消']
      })
    })

    this.setState({
      requestData: this.newData,
    });
  }

  initData = () => {
    this.newData = [];
  }

  componentDidMount() {
    this.getRequestData();
  }

  componentWillUnmount() {
    this.initData();
  }

  render() {
    return (
      <LocaleProvider locale={zh_CN}>
        <div className='apply'>
          <div>
						<Icon type="appstore" />
						<span className="apply-font">全部申请</span>
						<TitleBtn />
          </div>
          <QueryInfo />
          <TableInfo data={this.state.requestData} />
        </div> 
      </LocaleProvider>
    );
  }
}

export default All;